package com.lekang.controller;

import com.github.pagehelper.PageInfo;
import com.lekang.R;
import com.lekang.ZcqEntity.*;
import com.lekang.le.service.BillZcqService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/bill")
@Log
public class BillZcqController {
    @Autowired
    private BillZcqService billZcqService;
    @GetMapping("/list")
    public R list( @RequestParam(value ="billNo",required = false ) String billNo,
                   @RequestParam(value = "name",required = false) String elderlyName,
                   @RequestParam(value = "idCard" ,required = false) String elderlyIdCard,
                   @RequestParam("status") String transactionStatus,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageInfo<BillInfoDTO> billInfoDTOS = billZcqService.list(billNo,elderlyName,elderlyIdCard,transactionStatus,pageNum, pageSize);
        return R.ok(billInfoDTOS);
    }
    @GetMapping("/detail")
    public R detail(@RequestParam String billNo){
        BillInfoDTO billInfoDTO = billZcqService.detail(billNo);
        return R.ok(billInfoDTO);
    }
    @PutMapping("/cancel")
    public R cancel(@RequestParam String billNo){
       Integer result = billZcqService.cancel(billNo);
        return result > 0 ? R.ok() : R.error("取消失败");
    }
    @GetMapping("/refund")
    public R refund(RefundRecordQuery refundRecordQuery){
PageInfo<RefundRecord> refundRecords =billZcqService.refund(refundRecordQuery);
log.info(refundRecordQuery.toString());
log.info(refundRecords.toString());
        return R.ok(refundRecords);
    }
    @PutMapping("/pay")
    public R pay(@RequestParam String billNo){
        Integer result = billZcqService.pay(billNo);
        return result > 0 ? R.ok() : R.error("支付失败");
    }
    @GetMapping("elderlyList")
    public R elderlyList(){
        List<String> elderlyList = billZcqService.elderlyList();
        return R.ok(elderlyList);
    }
    @GetMapping("allBilledElderly")
    public R allBilledElderly(){
        List<String> elderlyList = billZcqService.allBilledElderly();
        return R.ok(elderlyList);
    }
    @PostMapping("generateMonthly")
    public R generateMonthly(@RequestParam String elderlyName){
        Integer result = billZcqService.generateMonthly(elderlyName);
        return result > 0 ? R.ok() : R.error("没有数据，生成失败");
    }
    @GetMapping("refundList")
    public R refundList(@RequestParam(required = false) String elderlyName,@RequestParam(required = false) String bedNo,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        PageInfo<DebtOverdueVo> DebtOverdueVoList = billZcqService.refundList(elderlyName,bedNo,pageNum,pageSize);
        return R.ok(DebtOverdueVoList);
    }
    @GetMapping("elderlyBills")
    public R elderlyBills(@RequestParam String elderlyName){
        List<BillDetailVoZcq> elderlyBills = billZcqService.elderlyBills(elderlyName);
        return R.ok(elderlyBills);
    }
}
